package com.example.gulimall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.example.gulimall.product.vo.SpuSaveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.common.entity.product.SpuInfoEntity;
import com.example.gulimall.product.service.SpuInfoService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;



/**
 * spu信息
 *
 * @author zyred
 * @email zyred@163.com
 * @date 2021-08-23 10:31:18
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = spuInfoService.queryPage(params);
        return R.ok().put("page", page);
    }


    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);
        return R.ok().put("spuInfo", spuInfo);
    }

    @PostMapping("/{spuId}/up")
    public R up(@PathVariable("spuId") Long spuId){
		spuInfoService.up(spuId);
        return R.ok();
    }

    @RequestMapping("/save")
    public R save(@RequestBody SpuSaveVo spuInfo){
        this.spuInfoService.saveSpuInfo(spuInfo);
        return R.ok();
    }

    @RequestMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);
        return R.ok();
    }

    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }


    @PostMapping("/spuInfoBySkuIds")
    public List<SpuInfoEntity> getSpuInfoBySkuIds(@RequestBody List<Long> skuIds){
        return this.spuInfoService.getSpuInfoBySkuIds(skuIds);
    }
}
